package com.boge.ai.advisor;

import org.springframework.ai.chat.client.advisor.api.*;
import reactor.core.publisher.Flux;

public class SimpleLoggerAdvisor implements CallAroundAdvisor, StreamAroundAdvisor {

    @Override
    public String getName() { return "SimpleLoggerAdvisor"; }
    @Override
    public int getOrder() { return 0; } // 优先执行

    @Override
    public AdvisedResponse aroundCall(AdvisedRequest req, CallAroundAdvisorChain chain) {
        System.out.println("请求前:" + req);
        AdvisedResponse res = chain.nextAroundCall(req);
        System.out.println("响应后:" + req);
        return res;
    }

    @Override
    public Flux<AdvisedResponse> aroundStream(AdvisedRequest req, StreamAroundAdvisorChain chain) {
        System.out.println("流式请求前:" + req);
        Flux<AdvisedResponse> flux = chain.nextAroundStream(req);
        return flux.doOnNext(res -> System.out.println("响应后:" + req));
    }
}

